package com.hrms.hrms_employee.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hrms.common.utils.RequestUtil;
import com.hrms.common.vo.PageVo;
import com.hrms.common.vo.ResultMessage;
import com.hrms.hrms_employee.entity.Station;
import com.hrms.hrms_employee.service.StationService;
import com.hrms.hrms_employee.vo.EmployeeGrowthDTO;
import com.hrms.hrms_employee.vo.stationDetail;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.time.YearMonth;
import java.util.List;
import java.util.Map;

/**
 * 岗位表(Station)表控制层
 *
 * @author makejava
 * @since 2025-01-15 13:55:34
 */
@RestController
@RequestMapping("station")
public class StationController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private StationService stationService;

    /**
     * 分页查询所有数据
     *
     * @param pageVo 分页对象
     * @param
     * @return 所有数据
     */
    @GetMapping
    public ResultMessage selectAll(PageVo pageVo, HttpServletRequest request) {
        Page<stationDetail> page = new Page<>(pageVo.getCurrent(), pageVo.getSize());
        RequestUtil requestUtil = new RequestUtil();
        Map<String, String> map = requestUtil.getParameterMap(request);
        Page<stationDetail> stationPage = this.stationService.pageInfo(page, map);
        return new ResultMessage(ResultMessage.Success,"",stationPage);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return success(this.stationService.getById(id));
    }

    /**
     * 获取月初月末员工数量
     * @return
     */
    @GetMapping("employeeGrowth")
    public ResultMessage getEmployeeStats() {
        YearMonth targetMonth = YearMonth.now();
        EmployeeGrowthDTO employeeGrowthDTO = this.stationService.getGrowthStats(targetMonth);
        return new ResultMessage(ResultMessage.Success,"",employeeGrowthDTO);
    }
    /**
     * 新增修改数据
     *
     * @param stationDetail 实体对象
     * @return 新增结果
     */
    @PostMapping
    public ResultMessage insertOrUpdate(@RequestBody stationDetail stationDetail) {
        this.stationService.saveOrUpdateInfo(stationDetail);
        return new ResultMessage(ResultMessage.Success,"");
    }


    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public ResultMessage delete(@RequestParam("id") Long id) {
        this.stationService.removeById(id);
        return new ResultMessage(ResultMessage.Success,"");
    }
}

